//
//  WBTitleButon.swift
//  GitWeibo
//
//  Created by 胡金东 on 2017/6/1.
//  Copyright © 2017年 胡金东. All rights reserved.
//

import UIKit

class WBTitleButon: UIButton {

     init(title:String?) {
        super.init(frame: CGRect())
        if title == nil {
            setTitle("首页", for: .normal)
        }else{
            setTitle(title! + " ", for: .normal)
            setImage(UIImage(named:"navigationbar_arrow_down"), for: .normal)
            setImage(UIImage(named:"navigationbar_arrow_up"), for: .selected)
        }
        titleLabel?.font = UIFont.boldSystemFont(ofSize: 17)
        setTitleColor(UIColor.darkGray, for: .normal)
        sizeToFit()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        guard  let titleLabel = titleLabel,
               let imageView = imageView else {
            return
        }
        titleLabel.frame.origin.x = 0
        /// - 将imageView的x向右平移label宽度
        imageView.frame.origin.x = titleLabel.bounds.width
        
    }

}
